﻿using ManagementClinic.App.Common;
using ManagementClinic.App.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ManagementClinic.App.View
{
    /// <summary>
    /// Interaction logic for TabControlMain.xaml
    /// </summary>
    public partial class TabControlMain : UserControl
    {
        public static TabControl tabControl;
        public TabControlMain()
        {
            InitializeComponent();
            tabControl = TabControlContent;
            this.DataContext = new TabViewModel();
            LoadTabItemsDefaul();
        }

        public void LoadTabItemsDefaul()
        {
            TabControlMain.AddTabControl(Const.TabControl.DichVu, new fromUserView());
            //TabControlMain.AddTabControl(Const.TabControl.BacSi, new fromUserView());
            //TabControlMain.AddTabControl(Const.TabControl.TinhThanh, new fromUserView());
        }

        public static  TabControl TabControl
        {
            get { return tabControl; }
        }
        public static bool AddTabControl(string tilte, UserControl userControl)
        {
            try
            {
                bool isExit = false;
                TabItem item = new TabItem();
                item.Header = tilte;
                item.Content = userControl;
                var listTabItem = TabControl.Items;

                foreach (var item1 in listTabItem)
                {
                    if (((TabItem)item1).Header.Equals(tilte))
                    {
                        tabControl.SelectedItem = (TabItem)item1;
                        isExit = true;
                    }
                }
                if (!isExit)
                    TabControl.Items.Add(item);
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
